package cryptology1

import (
	"crypto/ecdsa"
	"crypto/elliptic"
	"crypto/rand"
	"crypto/x509"
	"encoding/pem"
	"os"
)

func ECCprivateKey(){
	//1.生成密钥对
	privateKey, _ := ecdsa.GenerateKey(elliptic.P224(), rand.Reader)
	//2.X509证书编码
	ecPrivateKey, _:= x509.MarshalECPrivateKey(privateKey)
	//3.生成pem文件
	block:=pem.Block{
		Type:"ecc ecPrivateKey", 
		Bytes:ecPrivateKey,
	}
	file, _ := os.Create("ECCprivateKey.pem")
	pem.Encode(file, &block)

	//1.生成公钥
	publicKey := privateKey.PublicKey
	//2.X509证书编码
	ecPublicKey, _:= x509.MarshalPKIXPublicKey(&publicKey)
	//3.生成pem文件
	block=pem.Block{
		Type:    "ecc ecPublicKey",
		Bytes:   ecPublicKey,
	}
	file,_=os.Create("ECCpublicKey.pem")

	pem.Encode(file, &block)

}


